// pages/admin.js
const db=wx.cloud.database().collection('apply').orderBy('time','desc')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    background:['../../img/1.jpg','../../img/2.jpg','../../img/3.jpg','../../img/4.jpg','../../img/5.jpg'],
    list:[],
    isred:false,
    major:''
  },
  showmess:function(e){
    wx.navigateTo({
      url: '/pages/detail/detail?id='+e.currentTarget.id,
    })
 },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      major:options.major
    })

  },
  myapply:function(){
    const that=this
    
    db.where({
      major:that.data.major
    }).get({
      success:function(res){
        console.log(res)
        that.setData({
          list:res.data,
          isred:true
        })
      }
    })
  },
  unapply:function(){
    const that=this
  
    db.where({
      major:that.data.major,
      status:'审批中'
    }).get({
      success:function(res){
        console.log(res)
        that.setData({
          list:res.data,
          isred:false
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    if (typeof this.getTabBar === 'function' &&
    this.getTabBar()) {
    this.getTabBar().setData({
      selected: 0,
      list:[{
        "pagePath": "/pages/admin/admin",
        "text": "首页",
        "iconPath": "/img/index.png",
        "selectedIconPath": "/img/index_active.png"
      },
      {
        "pagePath": "/pages/my/my",
        "text": "我的",
        "iconPath": "/img/my.png",
        "selectedIconPath": "/img/my_active.png"
      }]
    })
  }
  const that=this
  db.where({
    major:that.data.major,
    status:'审批中'
  }).get({
  success:function(res){
    console.log(res)
    that.setData({
      list:res.data,
      isred:false
    })
  }
})
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})